//
//  MagzineDetailViewController.m
//  TextApplication
//
//  Created by dllo on 16/9/3.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "MagzineDetailViewController.h"
#import "TextView.h"
#import "UMSocialData.h"
#import "UMSocialSnsService.h"
#import "UMSocial.h"
#import "UMSocialSnsData.h"


@interface MagzineDetailViewController () <UMSocialUIDelegate>

@property (nonatomic, copy) NSString *url;
@property (nonatomic, strong) UIWebView *webView;

@end

@implementation MagzineDetailViewController

- (void)viewWillAppear:(BOOL)animated {
    self.navigationController.navigationBar.hidden = NO;

    self.webView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
    self.webView.backgroundColor = [UIColor colorWithWhite:0.176 alpha:1.000];
}

- (void)viewDidDisappear:(BOOL)animated {
    self.navigationController.navigationBar.hidden = YES;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"良仓杂志";
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithWhite:0.172 alpha:1.000];
    self.view.backgroundColor = [UIColor colorWithWhite:0.094 alpha:1.000];

    UIButton *left = [TextView createButtonWithImage:[UIImage imageNamed:@"10"]];
    [left addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:left];
    UIButton *secButton = [TextView createButtonWithImage:[UIImage imageNamed:@"31"]];
    [secButton addTarget:self action:@selector(shareClick:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:secButton];

    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 108)];
    self.webView.backgroundColor = [UIColor colorWithWhite:0.176 alpha:1.000];
    self.url = self.dataArray[self.sectionSuffix][self.rowSuffix][@"topic_url"];
       NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", self.dataArray[self.sectionSuffix][self.rowSuffix][@"topic_url"]]]];
    [self.webView loadRequest:request];
    [self.view addSubview:self.webView];
}

- (void)backClick:(UIButton *)nutton {
    [self.navigationController popToRootViewControllerAnimated:NO];
}

- (void)shareClick:(UIButton *)button {
//    NSLog(@"怎么回事儿");
    NSURL *url = [NSURL URLWithString:self.url];
    NSString *string = [NSString stringWithFormat:@"%@", url];
    
    [UMSocialData defaultData].extConfig.title = string;
//
//    [UMSocialData defaultData].extConfig.wechatSessionData.url = @"http://user.qzone.qq.com/692382667";
//    [UMSocialData defaultData].extConfig.wechatTimelineData.url = @"http://user.qzone.qq.com/692382667";
//    [UMSocialData defaultData].extConfig.wechatFavoriteData.url = @"http://user.qzone.qq.com/692382667";
//    [UMSocialData defaultData].extConfig.qqData.url = @"http://user.qzone.qq.com/692382667";
    
        [UMSocialSnsService presentSnsIconSheetView:self
                                        appKey:@"57e3a228e0f55ace8d003d06"
                                      shareText:string
                                     shareImage:[UIImage imageNamed:@"icon.png"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina  ,nil]
                                       delegate:nil];

//    [UMSocialData defaultData].extConfig.title = @"分享的title";
//    [UMSocialData defaultData].extConfig.wechatSessionData.url = @"http://baidu.com";
    // 记住这里填写的是友盟的appKey
//    [UMSocialSnsService presentSnsIconSheetView:self
//                                         appKey:@"57e3a228e0f55ace8d003d06"
//                                      shareText:string
//                                     shareImage:[UIImage imageNamed:@"icon"]
//                                shareToSnsNames:@[UMShareToWechatSession,UMShareToWechatTimeline,UMShareToSina,UMShareToQQ,UMShareToQzone]
//                                       delegate:self];
//}

//-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
//{
//    //根据`responseCode`得到发送结果,如果分享成功
//    if(response.responseCode == UMSResponseCodeSuccess)
//    {
//        //得到分享到的平台名
//        NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
//    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
